include $(TOPDIR)/rules.mk

PKG_NAME:=cliprobe
PKG_VERSION:=2017-03-30_01
PKG_BASE_NAME:=cliprobe

PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=https://gitee.com/insk/cliprobe.git
PKG_SOURCE_PROTO:=git
PKG_SOURCE_SUBDIR:=$(PKG_NAME)-$(PKG_VERSION)
PKG_SOURCE_VERSION:=master
PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_BASE_NAME)-$(PKG_VERSION)

include $(INCLUDE_DIR)/package.mk
include $(INCLUDE_DIR)/cmake.mk

define Package/cliprobe
  SECTION:=base
  CATEGORY:=Utilities
  DEFAULT:=n
  TITLE:=probe wifi client
  URL:=http://wirelesser.net/
  DEPENDS:=+libradiotap +libpthread +libopenssl +libpcap +libcurl
endef

define Package/cliprobe/config
	source "$(SOURCE)/config.in"
endef

define Package/cliprobe/description
probe wifi client
endef

ifdef CONFIG_USEPCAP
	CONFIG_USEPCAP="ON"
else
	CONFIG_USEPCAP="OFF"
endif

ifdef CONFIG_APFAKE
	CONFIG_APFAKE="ON"
else
	CONFIG_APFAKE="OFF"
endif

ifdef CONFIG_FIVETUPLE
	CONFIG_FIVETUPLE ="ON"
else
	CONFIG_FIVETUPLE ="OFF"
endif

ifdef CONFIG_REPORT_FILE
	CONFIG_REPORT_FILE="ON"
else
	CONFIG_REPORT_FILE="OFF"
endif
	
ifdef CONFIG_REPORT_UDP
	CONFIG_REPORT_UDP="ON"
else
	CONFIG_REPORT_UDP="OFF"
endif

ifdef CONFIG_REPORT_CURL
	CONFIG_REPORT_CURL="ON"
else
	CONFIG_REPORT_CURL="OFF"
endif

ifdef CONFIG_L7ANALYSE
	CONFIG_L7ANALYSE="ON"
else
	CONFIG_L7ANALYSE="OFF"
endif

ifdef CONFIG_HTTPDATA
	CONFIG_HTTPDATA="ON"
else
	CONFIG_HTTPDATA="OFF"
endif

ifdef CONFIG_DNSALZ
	CONFIG_DNSALZ="ON"
else
	CONFIG_DNSALZ="OFF"
endif

define Build/Configure
	(cd $(PKG_BUILD_DIR); \
		CFLAGS="$(TARGET_CFLAGS) $(EXTRA_CFLAGS)" \
		CXXFLAGS="$(TARGET_CFLAGS) $(EXTRA_CFLAGS)" \
		LDFLAGS="$(TARGET_LDFLAGS) $(EXTRA_LDFLAGS)" \
		cmake \
			-DIN_OPENWRT=1 \
			-DUSEPCAP=$(CONFIG_USEPCAP) \
			-DAPFAKE=$(CONFIG_APFAKE) \
			-DREPORT_FILE=$(CONFIG_REPORT_FILE) \
			-DREPORT_UDP=$(CONFIG_REPORT_UDP) \
			-DREPORT_CURL=$(CONFIG_REPORT_CURL) \
			-DL7ANALYSE=$(CONFIG_L7ANALYSE) \
			-DHTTPDATA=$(CONFIG_HTTPDATA) \
			-DDNSALZ=$(CONFIG_DNSALZ) \
			-DFIVETUPLE=$(CONFIG_FIVETUPLE) \
			-DCMAKE_SYSTEM_NAME=Linux \
			-DCMAKE_SYSTEM_VERSION=1 \
			-DCMAKE_SYSTEM_PROCESSOR=$(ARCH) \
			-DCMAKE_BUILD_TYPE=Release \
			-DCMAKE_C_FLAGS_RELEASE="-DNDEBUG" \
			-DCMAKE_CXX_FLAGS_RELEASE="-DNDEBUG" \
			-DCMAKE_C_COMPILER="$(CMAKE_C_COMPILER)" \
			-DCMAKE_C_COMPILER_ARG1="$(CMAKE_C_COMPILER_ARG1)" \
			-DCMAKE_CXX_COMPILER="$(CMAKE_CXX_COMPILER)" \
			-DCMAKE_CXX_COMPILER_ARG1="$(CMAKE_CXX_COMPILER_ARG1)" \
			-DCMAKE_EXE_LINKER_FLAGS:STRING="$(TARGET_LDFLAGS)" \
			-DCMAKE_MODULE_LINKER_FLAGS:STRING="$(TARGET_LDFLAGS)" \
			-DCMAKE_SHARED_LINKER_FLAGS:STRING="$(TARGET_LDFLAGS)" \
			-DCMAKE_AR="$(CMAKE_AR)" \
			-DCMAKE_RANLIB="$(CMAKE_RANLIB)" \
			-DCMAKE_FIND_ROOT_PATH="$(STAGING_DIR);$(TOOLCHAIN_DIR)" \
			-DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM=BOTH \
			-DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY \
			-DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=ONLY \
			-DCMAKE_STRIP=: \
			-DCMAKE_INSTALL_PREFIX=/usr \
			-DDL_LIBRARY=$(STAGING_DIR) \
			-DCMAKE_PREFIX_PATH=$(STAGING_DIR) \
			$(CMAKE_OPTIONS) \
		$(CMAKE_SOURCE_DIR) \
	)
endef


define Build/Compile
	$(MAKE) -C $(PKG_BUILD_DIR)
endef

define Package/cliprobe/install
	$(INSTALL_DIR) $(1)/usr/sbin
	$(INSTALL_DIR) $(1)/etc
	$(INSTALL_DIR) $(1)/etc/config
	$(INSTALL_DIR) $(1)/etc/init.d
	$(INSTALL_BIN) $(PKG_BUILD_DIR)/client/cliprobe $(1)/usr/sbin/
	$(INSTALL_DATA) $(PKG_BUILD_DIR)/client/cliprobe.cfg $(1)/etc/
	$(INSTALL_BIN) $(PKG_BUILD_DIR)/client/cliprobe.uci $(1)/etc/config/cliprobe
	$(INSTALL_BIN) $(PKG_BUILD_DIR)/client/cliprobe.init $(1)/etc/init.d/cliprobe
	$(INSTALL_DATA) $(PKG_BUILD_DIR)/client/pattern $(1)/etc/
	$(CP) -r $(PKG_BUILD_DIR)/client/scripts/* $(1)/usr/sbin/
endef

$(eval $(call BuildPackage,cliprobe))
#	$(INSTALL_BIN) $(PKG_BUILD_DIR)/client/zsftpput.sh $(1)/usr/sbin/
